package com.kylin.domain.marketing.provider;

import com.kylin.domain.marketing.command.FindCampaignByCommodityCommand;
import com.kylin.domain.marketing.command.FindMarketingCommodityCommand;
import com.kylin.domain.marketing.command.QueryMarketingCampaignCommand;
import com.kylin.domain.marketing.vo.MarketingCampaignVO;
import com.kylin.domain.marketing.vo.MarketingCommodityVO;
import com.kylin.shared.common.FunctionProvider;
import com.kylin.shared.common.PageResults;
import lombok.extern.slf4j.Slf4j;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.eventhandling.gateway.EventGateway;
import org.axonframework.queryhandling.QueryGateway;
import org.springframework.stereotype.Component;

/**
 * 麒麟营销操作类
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年12月20日 17:07
 */
@Slf4j
@Component
public final class MarketingProvider extends FunctionProvider {

    public MarketingProvider(QueryGateway queryGateway,
                             CommandGateway commandGateway,
                             EventGateway eventGateway) {
        super(queryGateway, commandGateway, eventGateway);
    }

    public MarketingCampaignVO findCampaignByCommodityId(Long commodityId) {
        FindCampaignByCommodityCommand command = FindCampaignByCommodityCommand.builder()
                .commodityId(commodityId).build();
        return executeQuery(command, MarketingCampaignVO.class);
    }

    public MarketingCommodityVO findMarketingCommodityLite(FindMarketingCommodityCommand command) {
        return executeQuery(command, MarketingCommodityVO.class);
    }

    public PageResults findMarketingBoard(QueryMarketingCampaignCommand command) {
        return executeQuery(command, PageResults.class);
    }
}
